<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	company			= Request("findCompany")
	compOrderNo	= Request("findOrderNo")
	compPrdCd		= Request("findPrdCd")
	compPrdNm		= Request("findPrdNm")

	SQLTitle = "-- ■■■■ 견적서 정보 그리드 List up ■■■■"
	
	'## 검색조건에 따른 조건절 만들기 
	If company <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " C.company LIKE '%" & company & "%'"
	End If 
	If compOrderNo <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " A.compOrderNo LIKE '%" & compOrderNo & "%'"
	End If 
	If compPrdCd <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " B.compPrdCd='" & compPrdCd & "'"
	End If 
	If compPrdNm <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " B.compPrdNm LIKE '%" & compPrdNm & "%'"
	End If 

	If addSql <> "" Then 
		addSql = " WHERE " & addSql 
	End If 

	SQL = "SELECT A.estCd, A.company, A.projectNm, A.totalPrice, CONVERT(varchar(10), A.addDt, 121) addDt, A.flag " & _
			"	FROM tblEstimate A LEFT JOIN tblEstimateArticle B ON A.estCd=B.estCd " & _
			"		GROUP BY A.estCd, A.company, A.projectNm, A.totalPrice, addDt, A.flag " & _
			"	ORDER BY A.flag DESC, A.estCd DESC" 

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<Estimate>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
			
			Response.write "	<Ests>" & vbcrlf
				Call mkXMLNode("estCd", rs("estCd"), 2)
				Call mkXMLNode("company", rs("company"), 2)
				Call mkXMLNode("projectNm", rs("projectNm"), 2)
				Call mkXMLNode("totalPrice", formatnumber(rs("totalPrice"),0), 2)
				Call mkXMLNode("addDt", rs("addDt"), 2)
				Call mkXMLNode("flag", Rs("flag"), 2)
			Response.write "	</Ests>" & vbcrlf

		Rs.movenext
		Loop 
	End If
	Response.write "</Estimate>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>